package cn.smbms.service.bill;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.smbms.dao.bill.BillDao;
import cn.smbms.dao.bill.BillDaoImpl;
import cn.smbms.pojo.Bill;


@Transactional
@Service("billService")
public class BillServiceImpl implements BillService {
	
	@Autowired
	@Qualifier("billDao")
	private BillDao billDao;
	public BillDao getBillDao() {
		return billDao;
	}
	public void setBillDao(BillDao billDao) {
		this.billDao = billDao;
	}
	public BillServiceImpl(){
		billDao=new BillDaoImpl();
	}
	
	@Transactional(propagation=Propagation.SUPPORTS)
	public boolean add(Bill bill) {
		// TODO Auto-generated method stub
		boolean flag = false;
		try {
			if(billDao.add(bill) > 0)
				flag = true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	@Transactional(propagation=Propagation.SUPPORTS)
	public List<Bill> getBillList(Map<String, Object> map) {
		// TODO Auto-generated method stub
		List<Bill> billList = null;
		try {
			billList = billDao.getBillList(map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return billList;
	}

	@Transactional(propagation=Propagation.SUPPORTS)
	public boolean deleteBillById(Integer delId) {
		// TODO Auto-generated method stub
		boolean flag = false;
		try {
			if(billDao.deleteBillById(delId) > 0)
				flag = true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	@Transactional(propagation=Propagation.SUPPORTS)
	public Bill getBillById(Integer id) {
		// TODO Auto-generated method stub
		Bill bill = null;
		try{
			bill = billDao.getBillById(id);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			bill = null;
		}
		return bill;
	}

	@Transactional(propagation=Propagation.SUPPORTS)
	public boolean modify(Bill bill) {
		// TODO Auto-generated method stub
		boolean flag = false;
		try {
			if(billDao.modify(bill) > 0)
				flag = true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

}
